package com.stox.parser;

import java.util.StringTokenizer;

import org.springframework.stereotype.Component;

import com.stox.model.Exchange;
import com.stox.model.Scrip;
import com.stox.model.Scrip.ScripType;

@Component
public class BseScripParser {

	public Scrip parse(Exchange exchange, String str){
		Scrip scrip = new Scrip();
		scrip.setExchangeCode(exchange.getCode());
		StringTokenizer t = new StringTokenizer(str,",",false);
		try{
			scrip.setCode(t.nextToken());
			scrip.setName(t.nextToken());
			t.nextToken();//scrip.setScripGroup(t.nextToken().trim().toUpperCase());
			//scrip.setType(t.nextToken().trim().toUpperCase());
			if(!"Q".equals(t.nextToken()))	return null;
			scrip.setScripType(ScripType.EQUITY);
			}catch(Exception e){
				e.printStackTrace();
				scrip = null;
			}
		return scrip;
	}
	
}
